package br.net.woodstock.tickettoride.api.seam.core.impl;

import javax.persistence.EntityManager;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Transactional;

import br.net.woodstock.rockframework.domain.Entity;
import br.net.woodstock.rockframework.persistence.orm.impl.JPAGenericRepository;
import br.net.woodstock.tickettoride.api.core.SimpleRepository;

@Name("simpleRepository")
@Scope(ScopeType.STATELESS)
public class SimpleRepositoryImpl implements SimpleRepository {

	private static final long	serialVersionUID	= -6146536936263260688L;

	@In("#{entityManager}")
	private EntityManager		entityManager;

	@Override
	@Transactional
	public void delete(final Entity<?> e) {
		new JPAGenericRepository(this.entityManager).delete(e);
	}

	@Override
	@Transactional
	public <E extends Entity<?>> E get(final E entity) {
		return new JPAGenericRepository(this.entityManager).get(entity);
	}

	@Override
	@Transactional
	public void save(final Entity<?> e) {
		new JPAGenericRepository(this.entityManager).save(e);
	}

	@Override
	@Transactional
	public void update(final Entity<?> e) {
		new JPAGenericRepository(this.entityManager).update(e);
	}

}
